package com.atguigu.spzx.manager.mapper;

import com.atguigu.spzx.model.vo.chat.chatmessageVo;
import com.atguigu.spzx.model.vo.chat.contactsVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChatMapper {
    List<contactsVo> GetAllContacts(Long userSId);

    void DeleteContacts(Long userSId, Long userRId);

    @Select("SELECT id FROM conversations WHERE (userSId = #{userSId} AND userRId = #{userRId})")
    Long findConversationIdByUserIds(Long userSId, Long userRId);

    @Insert("INSERT INTO messages (conversationId, senderId, content) VALUES (#{conversationId}, #{senderId}, #{content})")
    void saveMessage(Long conversationId, Long senderId, String content);

    @Insert("INSERT INTO conversations (userSId, userRId) VALUES (#{userSId}, #{userRId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Long createConversation(Long senderId, Long receiverId);

    @Select("SELECT id FROM conversations WHERE " +
            "(userSId = #{userSId} AND userRId = #{userRId}) or (userSId = #{userRId} AND userRId = #{userSId})")
    List<Integer> FindConversations(Long userSId, Long userRId);

    List<chatmessageVo> FindMessages(List conversationslist);
}
